package apiserver

import (
	"vite-tsc-gin/internal/apiserver/controllers/v1/user"
	"vite-tsc-gin/internal/apiserver/store/mysql"
	"vite-tsc-gin/pkg/middleware/auth"

	"github.com/gin-gonic/gin"
)

func initRouter(g *gin.Engine) {
	installMiddleware(g)
	installController(g)
}
func installMiddleware(g *gin.Engine) {
	// g.Use(middleware.Cors())
}
func installController(g *gin.Engine) *gin.Engine {
	jwtStrctegy := newJWTAuth().(auth.JWTStrategy)
	g.POST("/login", jwtStrctegy.LoginHandler)
	g.POST("/logout", jwtStrctegy.LogoutHandler)
	g.POST("/refresh", jwtStrctegy.RefreshHandler)
	storeIns, _ := mysql.GetMySQLFactoryOr(nil)
	userController := user.NewUserController(storeIns)
	v1 := g.Group("/v1")
	{
		userv1 := v1.Group("/users")
		{
			userv1.POST("", userController.Create)
		}
	}
	return g
}
